package com.dokimall.cart.vo;


import java.math.BigDecimal;
import java.util.List;

public class Cart {
    private List<CartItem> items;

    private Integer countNum; // 商品总数量

    private Integer countType; // 商品类型数量

    private BigDecimal totalAmount; // 购物车总价格

    private BigDecimal reduce = new BigDecimal("0.00"); // 减免价格

    public List<CartItem> getItems() {
        return items;
    }

    public void setItems(List<CartItem> items) {
        this.items = items;
    }

    public Integer getCountNum() {
        int count = 0;
        if(this.items!=null && this.items.size()>0){
            for (CartItem item : this.items) {
                count += item.getConut();
            }
        }
        return count;
    }


    public Integer getCountType() {
        return items.size();
    }

    public void setCountType(Integer countType) {
        this.countType = countType;
    }

    public BigDecimal getTotalAmount() {
        BigDecimal count = new BigDecimal("0");
        if(items !=null && items.size()>0){
            for (CartItem item :items) {
                if(item.getCheck()){
                    count = count.add(item.getTotalPrice());
                }

            }
        }
        // 减去优惠金额
        BigDecimal subtract = count.subtract(getReduce());
        return subtract;
    }


    public BigDecimal getReduce() {
        return reduce;
    }

    public void setReduce(BigDecimal reduce) {
        this.reduce = reduce;
    }
}
